﻿@Cofe ?= {}

pathUtils =
   
  
  ###
  Path Related routines
  ###
  extractFilepath1 : (path) ->    
    idx = path?.lastIndexOf('/')
    if (idx isnt -1) then path[0..idx] else ""    

  extractFilename : (path) ->
    idx = if path is undefined then -1 else path.lastIndexOf('/')
    if (idx isnt -1) then path[idx+1..path.length] else path  

  extractHeaderFilename : (path) ->
    (if path is "" 
    then "Root" 
    else @extractFilename(path))

  sizeInK : (size) ->
    Math.ceil(size / 1024)

  extractFilepath : (path) ->
    if (path is "") then undefined
    else 
      (
        idx = path.lastIndexOf('/')
        if idx is -1 
        then "" 
        else path.substring(0, idx)
      )

  getNextToken : (path, startFrom) ->
    if startFrom >= path.length then return undefined
    prevSlash = path.lastIndexOf('/', startFrom)
    startFrom  = if prevSlash is -1 then 0 else prevSlash + 1
    nextSlash = path.indexOf('/', startFrom)
    if (nextSlash is -1)
      return path[startFrom..path.length]
    else return path[startFrom..nextSlash-1]
    

 Cofe.pathUtils = pathUtils